package com.devilvan.fallback;

import com.devilvan.entity.Dept;
import com.devilvan.service.DeptClientService;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * 实现Fallback接口，需要重写create()方法
 */
@Component
public class DeptClientServiceFallbackFactory implements FallbackFactory {
    @Override
    public DeptClientService create(Throwable throwable) {
        return new DeptClientService() {
            @Override
            public boolean addDept(Dept dept) {
                return dept==null;
            }

            @Override
            public Dept queryDeptById(Long dept_id) {
                return new Dept()
                        .setDeptId(dept_id)
                        .setDeptName("该服务已关闭，请稍后再试  --@Hystrix")
                        .setDbSource("该服务已关闭，请稍后再试  --@Hystrix");
            }

            @Override
            public List<Dept> queryAllDepts() {
                ArrayList<Dept> list = new ArrayList<>();
                list.add(new Dept()
                        .setDeptName("该服务已关闭，请稍后再试  --@Hystrix")
                        .setDbSource("该服务已关闭，请稍后再试  --@Hystrix"));
                return list;
            }
        };
    }
}
